'''
实效督察页面测试
'''
from selenium.webdriver.common.by import By

from Lib.base.page_object.supervise.actual import Actual
import allure
from Lib.common.assert_class import AssertClass
import pytest
from Lib.common.get_data_by_mysql import MysqlAssert


@pytest.fixture(scope='class', autouse=True)
@pytest.mark.usefixtures('login')
def set_cls(login):
    TestActualSupervise.assertClass = AssertClass(login)
    TestActualSupervise.actual = Actual(login)


@allure.feature("实效督察测试")
class TestActualSupervise:

    @allure.title('督察列表筛选')
    def test_list(self, login):
        '''
        查看实效督察列表
        :return:
        '''
        with allure.step("根据督察来源进行筛选"):
            self.actual.list_by_source()
            assert_args = (By.XPATH, '//tbody//span[text()="区级督察"]')
            self.assertClass.make_assert_by_elements_text(args=assert_args, assert_data="区级督察")
        with allure.step("根据督察类型进行筛选"):
            self.actual.list_by_type()
            assert_args = (By.XPATH, '//tbody/tr/td[6]//span')
            self.assertClass.make_assert_by_elements_text(args=assert_args, assert_data="测试大类_请勿删除")
        with allure.step("根据督察状态进行筛选"):
            self.actual.list_by_status()
            assert_args = (By.XPATH, '//tbody/tr/td[10]//span')
            self.assertClass.make_assert_by_elements_text(args=assert_args, assert_data="复查通过")
        with allure.step("根据督察时间进行筛选"):
            self.actual.list_by_time()
            assert_args1 = (By.XPATH, '//tbody/tr[1]/td[8]//span')
            assert_args2 = (By.XPATH, '//tbody/tr[2]/td[8]//span')
            self.assertClass.make_assert_by_compare_time(args1=assert_args1, args2=assert_args2)

    @allure.title('督察列表查询')
    def test_search(self, login):
        '''
        根据关键字查询督察列表
        :return:
        '''
        with allure.step("根据督察人员进行搜索"):
            self.actual.search_by_people()
            assert_args = (By.XPATH, '//tbody/tr/td[4]//span')
            self.assertClass.make_assert_by_elements_text(args=assert_args, assert_data="申请人kb")
        with allure.step("根据责任部门进行搜索"):
            self.actual.search_by_department()
            assert_args = (By.XPATH, '//tbody/tr/td[5]//span')
            self.assertClass.make_assert_by_elements_text(args=assert_args, assert_data="流程测试部门")
        with allure.step("根据督察单号进行搜索"):
            self.actual.search_by_number()
            assert_args = (By.XPATH, '//tbody/tr/td[1]//span')
            self.assertClass.make_assert_by_elements_text(args=assert_args, assert_data="2022")

    @allure.title('执法督察审核')
    def test_review(self, login):
        '''
        根据关键字查询督察列表
        :return:
        '''
        with allure.step("一级审核"):
            self.actual.stair_review()
            assert_args = (By.XPATH, '//p[text()="已成功"]')
            self.assertClass.make_assert_by_text(args=assert_args, assert_data="已成功")
        with allure.step("二级审核"):
            self.actual.second_review()
            assert_args = (By.XPATH, '//p[text()="已成功"]')
            self.assertClass.make_assert_by_text(args=assert_args, assert_data="已成功")

    @allure.title('下发督察单')
    def test_send(self, login):
        '''
        下发督察单
        :return:
        '''
        self.actual.send()
        assert_args = (By.XPATH, '//p[text()="已成功"]')
        self.assertClass.make_assert_by_text(args=assert_args, assert_data="已成功")

    @allure.title('查看督察单详情')
    def test_detail(self, login):
        '''
        查看督察单详情
        :return:
        '''
        self.actual.detail()
        assert_args = (By.XPATH, '//span[text()="实效督察告知单"]')
        self.assertClass.make_assert_by_text(args=assert_args, assert_data="实效督察告知单")


if __name__ == '__main__':
    pytest.main(
        ['-v', '-s', './actual_supervise_test.py::TestActualSupervise'])
   
